#pragma once
#include "Unit.h"
#include "PlayerController.h"
#include "GameStateManager.h"

namespace game
{


	/**
	class	PlayerUnit
	Purpose	Allows a unit to be controlled by the player
	Usage	PlayerUnit * pu = new PlayerUnit("lizard",sf::Vector2f(128,128),getManager());
	Methods:
		Update:			calls Unit.update() and handles input
		HandleInput:	gets mouse/keyboard states and moves unit to point
	**/
	class PlayerUnit : public Unit, public PlayerController
	{
	public:
		PlayerUnit(string name, sf::Vector2f pos,game::GameStateManager * gsm)
				:Unit(				gsm->get_unit_factory()->CreateUnitRef(name, pos))
				,PlayerController(	gsm)
		{

		}
		~PlayerUnit(){};
		void Update()
		{
			Unit::Update();
			HandleInput();
		}
		void HandleInput()
		{
			sf::Vector2i	mp = get_game_state_manager()->getInput()->getMousePos();	
			sf::Vector2u	mouse_pos = sf::Vector2u(mp.x,mp.y);
			bool			right_mouse_pressed = get_game_state_manager()
							->getInput()->isMousePressed(sf::Mouse::Right);

			bool			left_button_pressed = get_game_state_manager()
							->getInput()->isKeyPressed(sf::Keyboard::Left);

			bool			right_button_pressed = get_game_state_manager()
							->getInput()->isKeyPressed(sf::Keyboard::Right);

			bool			up_button_pressed = get_game_state_manager()
							->getInput()->isKeyPressed(sf::Keyboard::Up);

			bool			down_button_pressed = get_game_state_manager()
							->getInput()->isKeyPressed(sf::Keyboard::Down);


			if (right_mouse_pressed)
			{
				MoveToPoint(mouse_pos);
			}

			if (up_button_pressed){MoveToNextCell("Up");}
			else if (down_button_pressed){MoveToNextCell("Down");}
			else if (left_button_pressed){MoveToNextCell("Left");}
			else if (right_button_pressed){MoveToNextCell("Right");}
		}
	};

}